<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0035)http://jdlsfl.iteye.com/blog/209388 -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" dir="ltr"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    
    <title>Java RPC通信机制之RMI -  - ITeye技术网站</title>
    <meta name="description" content="大卫注1： 写完CORBA系列后，本想接着写写其它几种典型的远程通信协议：RMI、XML-RPC、SOAP，但由于工作的原因，加之房子装修等麻烦事，一直没有心情动笔。今天接到装修公司老板电话说开工证要晚几天办下来，要停工4-5天，狂怒后突然有了静下心来完成原本想写的东西的想法，既来之，则安之（i.e.郁闷啊，郁闷啊，就习惯了...） 大卫注2： 这个系列基本上是一份笔记，没有加入太多我自己的东西，仅 ...">
    <meta name="keywords" content="  Java RPC通信机制之RMI">
    <link rel="shortcut icon" href="http://jdlsfl.iteye.com/images/favicon.ico" type="image/x-icon">
    <link rel="search" type="application/opensearchdescription+xml" href="http://jdlsfl.iteye.com/open_search.xml" title="ITeye">
    <link href="http://jdlsfl.iteye.com/rss" rel="alternate" title="" type="application/rss+xml">
    <link href="./Java RPC通信机制之RMI - - ITeye技术网站_files/blog.css" media="screen" rel="stylesheet" type="text/css">
<link href="./Java RPC通信机制之RMI - - ITeye技术网站_files/blue.css" media="screen" rel="stylesheet" type="text/css">
    <script type="text/javascript" async="" src="./Java RPC通信机制之RMI - - ITeye技术网站_files/ga.js"></script><script src="./Java RPC通信机制之RMI - - ITeye技术网站_files/application.js" type="text/javascript"></script>
    <script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-535605-1']);
  _gaq.push(['_setDomainName', '.iteye.com']);
  _gaq.push(['_setAllowHash', 'false']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

      
  <link href="./Java RPC通信机制之RMI - - ITeye技术网站_files/SyntaxHighlighter.css" media="screen" rel="stylesheet" type="text/css">
  <script src="./Java RPC通信机制之RMI - - ITeye技术网站_files/shCoreCommon.js" type="text/javascript"></script>
<script src="./Java RPC通信机制之RMI - - ITeye技术网站_files/hotkey.js" type="text/javascript"></script>
  <script src="./Java RPC通信机制之RMI - - ITeye技术网站_files/code_favorites.js" type="text/javascript"></script>
  <style>
    div#main {background-color: transparent; border: 0; padding: 0px; width: 740px;}
  </style>
  <link href="./Java RPC通信机制之RMI - - ITeye技术网站_files/ui.css" media="screen" rel="stylesheet" type="text/css">
  <script src="./Java RPC通信机制之RMI - - ITeye技术网站_files/compress.js" type="text/javascript"></script>
  </head>
  <body>
    <div id="header">
      <div id="blog_site_nav">
  <a href="http://www.iteye.com/" class="homepage">首页</a>
  <a href="http://www.iteye.com/news">新闻</a>
  <a href="http://www.iteye.com/forums">论坛</a>
  <a href="http://www.iteye.com/ask">问答</a>
  <a href="http://www.iteye.com/blogs">博客</a>
  <a href="http://www.iteye.com/job">招聘</a>
  <a href="http://jdlsfl.iteye.com/blog/209388#" onclick="return false;" id="msna"><u>更多</u> <small>▼</small></a>
  <div class="quick_menu" style="display:none;">
    <a href="http://www.iteye.com/groups">群组</a>
    <a href="http://www.iteye.com/search">搜索</a>
  </div>
</div>
      <div id="user_nav">
      <a href="http://jdlsfl.iteye.com/login" class="welcome" title="登录">您还未登录 !</a>
    <a href="http://www.iteye.com/all" style="color:red">我的应用</a>
    <a href="http://jdlsfl.iteye.com/login">登录</a>
    <a href="http://jdlsfl.iteye.com/signup" class="nobg">注册</a>
  </div>
    </div>

    <div id="page">
      <div id="branding" class="clearfix">
        <div id="blog_name"><h1><a href="http://jdlsfl.iteye.com/">jdlsfl</a></h1></div>
        <div id="blog_preview">
          
        </div>
        <div id="blog_domain">永久域名 <a href="http://jdlsfl.iteye.com/">http://jdlsfl.iteye.com</a></div>
      </div>
      
      <div id="content" class="clearfix">
        <div id="main">
          


          


<div class="blog_main"> 
  <div class="blog_nav">
    
    <div class="pre_next">
      <a href="http://jdlsfl.iteye.com/blog/205660" class="next" title="[转]如何操作Cookie ">[转]如何操作Cookie </a>
      |
      <a href="http://jdlsfl.iteye.com/blog/209470" class="pre" title="CSS模块化设计——从空格谈起">CSS模块化设计——从空格谈起</a>
    </div>
  </div>
  <div class="blog_title">
    <div class="date"><span class="year">2008</span><span class="sep_year">-</span><span class="month">05</span><span class="sep_month">-</span><span class="day">16</span></div>
    <h3><a href="./Java RPC通信机制之RMI - - ITeye技术网站_files/Java RPC通信机制之RMI - - ITeye技术网站.htm">Java RPC通信机制之RMI</a></h3>
                    
  </div>

  <div class="blog_content">
    <p style="margin: 0in 0in 0pt;"><span lang="ZH-CN" style="">大卫注</span><span style="font-size: 10pt; color: green; font-family: &#39;Courier New&#39;;">1</span><span lang="ZH-CN" style="">：</span><span style="font-size: 10pt; color: green; font-family: &#39;Courier New&#39;;"></span></p>
<p style="margin: 0in 0in 0pt;"><span lang="ZH-CN" style="">写完</span><span style="font-size: 10pt; color: green; font-family: &#39;Courier New&#39;;">CORBA</span><span lang="ZH-CN" style="">系列后，本想接着写写其它几种典型的远程通信协议：</span><span style="font-size: 10pt; color: green; font-family: &#39;Courier New&#39;;">RMI</span><span lang="ZH-CN" style="">、</span><span style="font-size: 10pt; color: green; font-family: &#39;Courier New&#39;;">XML-RPC</span><span lang="ZH-CN" style="">、</span><span style="font-size: 10pt; color: green; font-family: &#39;Courier New&#39;;">SOAP</span><span lang="ZH-CN" style="">，但由于工作的原因，加之房子装修等麻烦事，一直没有心情动笔。今天接到装修公司老板电话说开工证要晚几天办下来，要停工</span><span style="font-size: 10pt; color: green; font-family: &#39;Courier New&#39;;">4-5</span><span lang="ZH-CN" style="">天，狂怒后突然有了静下心来完成原本想写的东西的想法，既来之，则安之（</span><span style="font-size: 10pt; color: green; font-family: &#39;Courier New&#39;;">i.e.</span><span lang="ZH-CN" style="">郁闷啊，郁闷啊，就习惯了</span><span style="font-size: 10pt; color: green; font-family: &#39;Courier New&#39;;">...</span><span lang="ZH-CN" style="">）</span><span style="font-size: 10pt; color: green; font-family: &#39;Courier New&#39;;"></span></p>
<p style="margin: 0in 0in 0pt;"><span lang="ZH-CN" style="">大卫注</span><span style="font-size: 10pt; color: green; font-family: &#39;Courier New&#39;;">2</span><span lang="ZH-CN" style="">：</span><span style="font-size: 10pt; color: green; font-family: &#39;Courier New&#39;;"></span></p>
<p style="margin: 0in 0in 0pt;"><span lang="ZH-CN" style="">这个系列基本上是一份笔记，没有加入太多我自己的东西，仅仅记录了自己在使用过程中遇到的问题，及其解决办法。</span><span style="font-family: &#39;Courier New&#39;;"></span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-family: &#39;Courier New&#39;;"><font size="3">&nbsp;</font></span></p>
<p style="margin: 0in 0in 0pt;"><span lang="ZH-CN" style="">在传统的</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">RPC</span><span lang="ZH-CN" style="">编程接口逐渐淡出人们视线的同时，新的、更便于使用且附加了更多特性的</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">RPC</span><span lang="ZH-CN" style="">编程接口也不断涌现，</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">CORBA</span><span lang="ZH-CN" style="">作为分布式对象计算技术的典范，在很长一段时间内极大地吸引了大家的注意，但是由于</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">CORBA</span><span lang="ZH-CN" style="">规范试图覆盖过多的内容，使得</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">CORBA</span><span lang="ZH-CN" style="">显得过于复杂，也极大地限制了</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">CORBA</span><span lang="ZH-CN" style="">的应用范围，本系列将向大家介绍几种轻量级的，更适于在</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">Java</span><span lang="ZH-CN" style="">开发中使用的</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">RPC</span><span lang="ZH-CN" style="">编程接口：</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">RMI</span><span lang="ZH-CN" style="">、</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">XML-RPC</span><span lang="ZH-CN" style="">、</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">SOAP</span><span lang="ZH-CN" style="">。</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;"></span></p>
<h2 style="margin: 12pt 0in 3pt;"><em>RMI<span lang="ZH-CN" style="">（</span>Remote Method Invocation<span lang="ZH-CN" style="">）</span></em></h2>
<p style="margin: 0in 0in 0pt;"><span lang="ZH-CN" style="">与本系列将介绍的其它两种</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">RPC</span><span lang="ZH-CN" style="">编程接口不同，</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">RMI</span><span lang="ZH-CN" style="">（</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">Remote Method Invocation</span><span lang="ZH-CN" style="">）显得有些老旧，它是在</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">Java-IDL</span><span lang="ZH-CN" style="">加入</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">J2SE</span><span lang="ZH-CN" style="">之前被引入的。</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">RMI</span><span lang="ZH-CN" style="">开发流程与</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">CORBA</span><span lang="ZH-CN" style="">如出一辙（从出现的时间上无法确定</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">RMI</span><span lang="ZH-CN" style="">是否是按照</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">CORBA</span><span lang="ZH-CN" style="">规范定制的），因此，其开发过程相对比较烦琐，但是由于</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">RMI</span><span lang="ZH-CN" style="">是</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">EJB</span><span lang="ZH-CN" style="">的基础，因此，它在</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">Java</span><span lang="ZH-CN" style="">开发中具有十分重要的地位。</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;"></span></p>
<p style="margin: 0in 0in 0pt;"><span lang="ZH-CN" style="">以下是创建远程方法调用的</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">5</span><span lang="ZH-CN" style="">个步骤：</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;"></span></p>
<p style="margin: 0in 0in 0pt 0.25in; text-indent: -0.25in;"><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">1.<span style="font: 7pt &#39;Times New Roman&#39;;">&nbsp;&nbsp; </span></span><span lang="ZH-CN" style="">定义一个扩展了</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">Remote</span><span lang="ZH-CN" style="">接口的接口，该接口中的每一个方法必须声明它将产生一个</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">RemoteException</span><span lang="ZH-CN" style="">异常；</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;"></span></p>
<p style="margin: 0in 0in 0pt 0.25in; text-indent: -0.25in;"><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">2.<span style="font: 7pt &#39;Times New Roman&#39;;">&nbsp;&nbsp; </span></span><span lang="ZH-CN" style="">定义一个实现该接口的类；</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;"></span></p>
<p style="margin: 0in 0in 0pt 0.25in; text-indent: -0.25in;"><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">3.<span style="font: 7pt &#39;Times New Roman&#39;;">&nbsp;&nbsp; </span></span><span lang="ZH-CN" style="">使用</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">rmic</span><span lang="ZH-CN" style="">程序生成远程实现所需的存根和框架；</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;"></span></p>
<p style="margin: 0in 0in 0pt 0.25in; text-indent: -0.25in;"><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">4.<span style="font: 7pt &#39;Times New Roman&#39;;">&nbsp;&nbsp; </span></span><span lang="ZH-CN" style="">创建一个客户程序和服务器进行</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">RMI</span><span lang="ZH-CN" style="">调用；</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;"></span></p>
<p style="margin: 0in 0in 0pt 0.25in; text-indent: -0.25in;"><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">5.<span style="font: 7pt &#39;Times New Roman&#39;;">&nbsp;&nbsp; </span></span><span lang="ZH-CN" style="">启动</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">rmiregistry</span><span lang="ZH-CN" style="">并运行自己的服务程序和客户程序。</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;"></span></p>
<p style="margin: 0in 0in 0pt;"><span lang="ZH-CN" style="">下面举一个简单、而且被无数次引用的例子：</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">Echo</span><span lang="ZH-CN" style="">。</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;"></span></p>
<h3 style="margin: 12pt 0in 3pt;">1<span lang="ZH-CN" style="">、定义</span>Echo<span lang="ZH-CN" style="">接口</span></h3>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; color: green; font-family: &#39;Courier New&#39;;">//Echo.java</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; color: green; font-family: &#39;Courier New&#39;;">//The Echo remote interface</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">package demo.rmi;</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">&nbsp;</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">import java.rmi.*;</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">&nbsp;</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; color: blue; font-family: &#39;Courier New&#39;;">public</span><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"> <span style="color: blue;">interface</span> Echo extends Remote {</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>String echo(String msg) throws RemoteException;</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">}</span></p>
<h3 style="margin: 12pt 0in 3pt;">2<span lang="ZH-CN" style="">、实现</span>Echo<span lang="ZH-CN" style="">接口</span></h3>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; color: green; font-family: &#39;Courier New&#39;;">//EchoServer.java</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; color: green; font-family: &#39;Courier New&#39;;">//The implementation of the Echo remote object</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">package demo.rmi;</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">&nbsp;</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">import java.net.*;</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">import java.rmi.*;</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">import java.rmi.registry.*;</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">import java.rmi.server.*;</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">&nbsp;</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; color: blue; font-family: &#39;Courier New&#39;;">public</span><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"> <span style="color: blue;">class</span> EchoServer</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>extends UnicastRemoteObject</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>implements Echo {</span></p>
<p style="margin: 0in 0in 0pt;"><span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">//默认构件器，也要“掷”出</span></span><span style="font-size: 10pt; color: green; font-family: &#39;Courier New&#39;;">RemoteException</span><span style="">违例</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">public</span> EchoServer() throws RemoteException {</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>super();</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">&nbsp;</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">public</span> String echo(String msg) throws RemoteException {</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">return</span> <span style="color: maroon;">"Echo: "</span> + msg;</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">&nbsp;</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: blue;">void</span> main(String [] args) {</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 10pt; color: green; font-family: &#39;Courier New&#39;;">/*</span><span style="">创建和安装一个安全管理器，令其支持</span><span style="font-size: 10pt; color: green; font-family: &#39;Courier New&#39;;">RMI</span><span style="">。</span><span style="">作为</span><span style="font-size: 10pt; color: green; font-family: &#39;Courier New&#39;;">Java</span><span style="">开发包的一部分，适用于</span><span style="font-size: 10pt; color: green; font-family: &#39;Courier New&#39;;">RMI</span><span style="">唯一一个是</span><span style="font-size: 10pt; color: green; font-family: &#39;Courier New&#39;;">RMISecurityManager.*/</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>System.setSecurityManager(<span style="color: blue;">new</span> RMISecurityManager());</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">&nbsp;</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">try</span> {</span></p>
<p style="margin: 0in 0in 0pt;"><span style=""><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">/*创建远程对象的一个或多个实例，下面是</span></span><span style="font-size: 10pt; color: green; font-family: &#39;Courier New&#39;;">EchoServer</span><span style="">对象*/</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>EchoServer es = <span style="color: blue;">new</span> EchoServer();</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="">/*向</span><span style="font-size: 10pt; color: green; font-family: &#39;Courier New&#39;;">RMI</span><span style="">远程对象注册表注册至少一个远程对象。一个远程对象拥有的方法即可生成指向其他远程对象的句柄，这样，客户到注册表里访问一次，得到第一个远程对象即可.*/</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">Naming.rebind(<span style="color: maroon;">"EchoServer"</span>, es);</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>System.out.println(<span style="color: maroon;">"Ready to provide echo service..."</span>);</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>} <span style="color: blue;">catch</span> (Exception e) {</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>e.printStackTrace();</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">}</span></p>
<p style="margin: 0in 0in 0pt;"><span lang="ZH-CN" style="">这个实现类使用了</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">UnicastRemoteObject</span><span lang="ZH-CN" style="">去连接</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">RMI</span><span lang="ZH-CN" style="">系统。在我们的例子中，我们是直接的从</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">UnicastRemoteObject</span><span lang="ZH-CN" style="">这个类上继承的，事实上并不一定要这样做，如果一个类不是从</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">UnicastRmeoteObject</span><span lang="ZH-CN" style="">上继承，那必须使用它的</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">exportObject()</span><span lang="ZH-CN" style="">方法去连接到</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">RMI</span><span lang="ZH-CN" style="">。（否则，运行时将被告知无法序列化。）</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;"></span></p>
<p style="margin: 0in 0in 0pt;"><span lang="ZH-CN" style="">如果一个类继承自</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">UnicastRemoteObject</span><span lang="ZH-CN" style="">，那么它必须提供一个构造函数并且声明抛出一个</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">RemoteException</span><span lang="ZH-CN" style="">对象（否则，会遇到编译错误）。当这个构造函数调用了</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">super()</span><span lang="ZH-CN" style="">，它就激活</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">UnicastRemoteObject</span><span lang="ZH-CN" style="">中的代码完成</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">RMI</span><span lang="ZH-CN" style="">的连接和远程对象的初始化。</span><span style="font-family: &#39;Courier New&#39;;"></span></p>
<h3 style="margin: 12pt 0in 3pt;">3<span lang="ZH-CN" style="">、运行</span>rmic<span lang="ZH-CN" style="">编译实现类，产生</span>_Stub<span lang="ZH-CN" style="">类</span></h3>
<p style="margin: 0in 0in 0pt;"><span lang="ZH-CN" style="">在</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">demo.rmi.EchoServer.java</span><span lang="ZH-CN" style="">上级目录下运行如下命令：</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;"></span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">rmic demo.rmi.EchoServer</span><span style="font-family: &#39;Courier New&#39;;"></span></p>
<h3 style="margin: 12pt 0in 3pt;">4<span lang="ZH-CN" style="">、编写客户程序</span></h3>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; color: green; font-family: &#39;Courier New&#39;;">//EchoClient.java</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; color: green; font-family: &#39;Courier New&#39;;">//Uses remote object EchoServer</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">package demo.rmi;</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">&nbsp;</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">import java.rmi.*;</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">import java.rmi.registry.*;</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">&nbsp;</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; color: blue; font-family: &#39;Courier New&#39;;">public</span><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"> <span style="color: blue;">class</span> EchoClient {</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: blue;">void</span> main(String [] args) {</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>System.setSecurityManager(<span style="color: blue;">new</span> RMISecurityManager());</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">&nbsp;</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">try</span> {</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>Echo t = (Echo)Naming.lookup(<span style="color: maroon;">"EchoServer"</span>);</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">&nbsp;</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">for</span> (<span style="color: blue;">int</span> i = 0; i &lt; 10; i++) {</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>System.out.println(t.echo(String.valueOf(i)));</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>} <span style="color: blue;">catch</span> (Exception e) {</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>e.printStackTrace();</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">}</span></p>
<h3 style="margin: 12pt 0in 3pt;">5<span lang="ZH-CN" style="">、运行</span></h3>
<p style="margin: 0in 0in 0pt;"><span lang="ZH-CN" style="">编码的工作就只有这些，现在可以依次启动</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">rmiregistry</span><span lang="ZH-CN" style="">（启动</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">rmiregistry</span><span lang="ZH-CN" style="">时可以附加一个端口，一般使用默认的端口</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">1099</span><span lang="ZH-CN" style="">即可，这是默认的</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">Naming Service</span><span lang="ZH-CN" style="">运行端口）、</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">EchoServer</span><span lang="ZH-CN" style="">、</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">EchoClient</span><span lang="ZH-CN" style="">了。但是，虽然有些</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">RMI</span><span lang="ZH-CN" style="">的资料没有提到，但你运行时不可避免会遇到如下两个错误：</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;"></span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">1</span><span lang="ZH-CN" style="">）</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;"></span></p>
<p style="margin: 0in 0in 0pt;"><span lang="ZH-CN" style="">原因很简单，</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">RMI Server/Client</span><span lang="ZH-CN" style="">程序试图通过</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">Socket</span><span lang="ZH-CN" style="">连接访问本机的</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">rmiregistry</span><span lang="ZH-CN" style="">服务（即</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">RMI</span><span lang="ZH-CN" style="">的</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">Naming Service</span><span lang="ZH-CN" style="">，其运行的默认端口是</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">1099</span><span lang="ZH-CN" style="">）。要解决这个问题，可以在运行</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">Server/Client</span><span lang="ZH-CN" style="">时指定一个</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">Policy</span><span lang="ZH-CN" style="">文件（关于</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">Policy</span><span lang="ZH-CN" style="">的更多信息，见参考</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">2</span><span lang="ZH-CN" style="">），如下：</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;"></span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">java -Djava.security.policy=demo/rmi/policyfile.txt demo.rmi.EchoServer</span><span style="font-family: &#39;Courier New&#39;;"></span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">Policy</span><span lang="ZH-CN" style="">文件的内容为：</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;"></span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">grant{</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>permission java.net.SocketPermission <span style="color: maroon;">"localhost:1099"</span>, <span style="color: maroon;">"connect, resolve"</span>;</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">};</span></p>
<p style="margin: 0in 0in 0pt;"><span lang="ZH-CN" style="">即允许访问本机的</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">1099</span><span lang="ZH-CN" style="">端口。</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;"></span></p>
<p style="margin: 0in 0in 0pt;"><span lang="ZH-CN" style="">或者干脆来个彻底开放：</span><span style="font-family: &#39;Courier New&#39;;"></span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">grant {</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>permission java.security.AllPermission <span style="color: maroon;">""</span>, <span style="color: maroon;">""</span>;</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">};</span></p>
<p style="margin: 0in 0in 0pt;"><font size="3"><span style="font-family: &#39;Courier New&#39;;">2</span><span lang="ZH-CN" style="">）</span></font><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;">java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>java.lang.ClassNotFoundException: demo.rmi.EchoServer_Stub</span></p>
<p style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &#39;Courier New&#39;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>...</span></p>
<p style="margin: 0in 0in 0pt;"><span lang="ZH-CN" style="">如果你凑巧用启动</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">rmiregistry</span><span lang="ZH-CN" style="">的终端窗口启动了</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">EchoServer</span><span lang="ZH-CN" style="">，那么你很走运，你看不到上面的错误，但如果你不是在看完这篇文章后就再也用不到</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">RMI</span><span lang="ZH-CN" style="">，那么，这个错误在那里等着你，</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;">:)</span><span lang="ZH-CN" style="">。</span><span style="font-size: 11pt; font-family: &#39;Courier New&#39;;"></span></p>
<p style="margin: 0in 0in 0pt;"><span lang="ZH-CN" style="">错误很明显，</span><span style=""></span></p>
  </div>

  

  <script type="text/javascript"><!--
google_ad_client = "pub-1076724771190722";
/* JE个人博客468x60 */
google_ad_slot = "5506163105";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript" src="./Java RPC通信机制之RMI - - ITeye技术网站_files/show_ads.js">
</script><ins style="display:inline-table;border:none;height:60px;margin:0;padding:0;position:relative;visibility:visible;width:468px"><ins id="aswift_0_anchor" style="display:block;border:none;height:60px;margin:0;padding:0;position:relative;visibility:visible;width:468px"><iframe allowtransparency="true" frameborder="0" height="60" hspace="0" marginwidth="0" marginheight="0" onload="var i=this.id,s=window.google_iframe_oncopy,H=s&amp;&amp;s.handlers,h=H&amp;&amp;H[i],w=this.contentWindow,d;try{d=w.document}catch(e){}if(h&amp;&amp;d&amp;&amp;(!d.body||!d.body.firstChild)){if(h.call){i+=&#39;.call&#39;;setTimeout(h,0)}else if(h.match){i+=&#39;.nav&#39;;w.location.replace(h)}s.log&amp;&amp;s.log.push(i)}" scrolling="no" vspace="0" width="468" id="aswift_0" name="aswift_0" style="left:0;position:absolute;top:0;"></iframe></ins></ins>
  
  

  <div class="blog_nav">
    <div class="pre_next">
      <a href="http://jdlsfl.iteye.com/blog/205660" class="next" title="[转]如何操作Cookie ">[转]如何操作Cookie </a>
      |
      <a href="http://jdlsfl.iteye.com/blog/209470" class="pre" title="CSS模块化设计——从空格谈起">CSS模块化设计——从空格谈起</a>
    </div>
  </div>

  <div class="blog_bottom">
    <ul>
      <li>11:45</li>
      <li>浏览 (2109)</li>
            <li><a href="http://jdlsfl.iteye.com/blog/209388#comments">评论</a> (1)</li>
      
      
      
            
      <li class="last"><a href="http://www.iteye.com/wiki/topic/209388" target="_blank" class="more">相关推荐</a></li>
    </ul>
  </div>

  <div class="blog_comment">
    <h5>评论</h5>
    <a id="comments" name="comments"></a>
    <div id="bc1283851">
  <div class="comment_title">
    1 楼
    <a href="http://sunwenran.iteye.com/" target="_blank">sunwenran</a>
    2009-12-07&nbsp;&nbsp;
    <a href="http://jdlsfl.iteye.com/blog/209388#" onclick="quote_comment(1283851);return false;">引用</a>
    
  </div>
  <div class="comment_content">在Java开发中使用的RPC编程接口：RMI、XML-RPC、SOAP。
<br>
<br>rmi xml-rpc都用过
<br>soap没接触过。
<br>有没有例子？</div>
</div>

    
    
  </div>

  <div class="blog_comment">
    <h5>发表评论</h5>
          
      
        <form action="./Java RPC通信机制之RMI - - ITeye技术网站_files/Java RPC通信机制之RMI - - ITeye技术网站.htm" id="comment_form" method="post" onsubmit="return false;">          


  <input type="hidden" id="editor_bbcode_flag" value="true">



<div id="editor_main"><div id="editor_wrapper" class="clearfix"><div id="bbcode_emotions"><h5>表情图标</h5><img src="./Java RPC通信机制之RMI - - ITeye技术网站_files/icon_biggrin.gif"><img src="./Java RPC通信机制之RMI - - ITeye技术网站_files/icon_smile.gif"><img src="./Java RPC通信机制之RMI - - ITeye技术网站_files/icon_sad.gif"><img src="./Java RPC通信机制之RMI - - ITeye技术网站_files/icon_surprised.gif"><img src="./Java RPC通信机制之RMI - - ITeye技术网站_files/icon_eek.gif"><img src="./Java RPC通信机制之RMI - - ITeye技术网站_files/icon_confused.gif"><img src="./Java RPC通信机制之RMI - - ITeye技术网站_files/icon_cool.gif"><img src="./Java RPC通信机制之RMI - - ITeye技术网站_files/icon_lol.gif"><img src="./Java RPC通信机制之RMI - - ITeye技术网站_files/icon_mad.gif"><img src="./Java RPC通信机制之RMI - - ITeye技术网站_files/icon_razz.gif"><img src="./Java RPC通信机制之RMI - - ITeye技术网站_files/icon_redface.gif"><img src="./Java RPC通信机制之RMI - - ITeye技术网站_files/icon_cry.gif"><img src="./Java RPC通信机制之RMI - - ITeye技术网站_files/icon_evil.gif"><img src="./Java RPC通信机制之RMI - - ITeye技术网站_files/icon_twisted.gif"><img src="./Java RPC通信机制之RMI - - ITeye技术网站_files/icon_rolleyes.gif"><img src="./Java RPC通信机制之RMI - - ITeye技术网站_files/icon_wink.gif"><img src="./Java RPC通信机制之RMI - - ITeye技术网站_files/icon_exclaim.gif"><img src="./Java RPC通信机制之RMI - - ITeye技术网站_files/icon_question.gif"><img src="./Java RPC通信机制之RMI - - ITeye技术网站_files/icon_idea.gif"><img src="./Java RPC通信机制之RMI - - ITeye技术网站_files/icon_arrow.gif"></div><div id="bbcode_controllers"><div id="bbcode_toolbar"><input type="button" value="B" id="button_bold"><input type="button" value="I" id="button_italic"><input type="button" value="U" id="button_underline"><input type="button" value="Quote"><input type="button" value="Code"><input type="button" value="List"><input type="button" value="Img"><input type="button" value="URL"><input type="button" value="Flash"><input type="button" value="Table"><br>字体颜色: <select id="select_color"><option value="black" style="color: black;">标准</option><option value="darkred" style="color: darkred;">深红</option><option value="red" style="color: red;">红色</option><option value="orange" style="color: orange;">橙色</option><option value="brown" style="color: brown;">棕色</option><option value="yellow" style="color: yellow;">黄色</option><option value="green" style="color: green;">绿色</option><option value="olive" style="color: olive;">橄榄</option><option value="cyan" style="color: cyan;">青色</option><option value="blue" style="color: blue;">蓝色</option><option value="darkblue" style="color: darkblue;">深蓝</option><option value="indigo" style="color: indigo;">靛蓝</option><option value="violet" style="color: violet;">紫色</option><option value="gray" style="color: gray;">灰色</option><option value="white" style="color: white;">白色</option><option value="black" style="color: black;">黑色</option></select>&nbsp;字体大小: <select id="select_font"><option value="0">标准</option><option value="xx-small">1 (xx-small)</option><option value="x-small">2 (x-small)</option><option value="small">3 (small)</option><option value="medium">4 (medium)</option><option value="large">5 (large)</option><option value="x-large">6 (x-large)</option><option value="xx-large">7 (xx-large)</option></select>&nbsp;对齐: <select id="select_align"><option value="0">标准</option><option value="left">居左</option><option value="center">居中</option><option value="right">居右</option></select></div><div id="bbcode_tooltip">提示：选择您需要装饰的文字, 按上列按钮即可添加上相应的标签</div><textarea class="validate-richeditor bad-words min-length-5" cols="40" id="editor_body" name="comment[body]" rows="20" style="width: 500px; height: 350px;"></textarea></div></div></div>


<script type="text/javascript">
  var editor = new Control.TextArea.Editor("editor_body", "bbcode", false);
</script>
          <p style="text-align:right;padding-right:30px;">您还没有登录，请<a href="http://jdlsfl.iteye.com/login">登录</a>后发表评论(快捷键 Alt+S / Ctrl+Enter) <input class="submit" id="quick_reply_button" name="commit" type="submit" value="提交"></p>
        </form>
        <script type="text/javascript">
          new HotKey("s",function() {$('quick_reply_button').click();},{altKey: true, ctrlKey: false});
          new HotKey(new Number(13),function() {$('quick_reply_button').click();},{altKey: false, ctrlKey: true});

          new Validation("comment_form", {immediate: false, onFormValidate: function(result, form){
    
            if(confirm('您需要登录以后才能执行这个操作，现在要登录吗？')) window.location.href = '/login';
    
        }});
        </script>
      
      </div>
</div>


<script type="text/javascript">
  dp.SyntaxHighlighter.HighlightAll('code', true, true);
  
  $$('#main .blog_content pre[name=code]').each(function(pre, index){ // blog content
    var post_id = 587320;
    var location = window.location;
    source_url = location.protocol + "//" + location.host + location.pathname + location.search;
    pre.writeAttribute('codeable_id', post_id);
    pre.writeAttribute('codeable_type', "Post");
    pre.writeAttribute('source_url', source_url);
    pre.writeAttribute('pre_index', index);
    pre.writeAttribute('title', 'Java RPC通信机制之RMI');
  });
  $$('#main .blog_comment > div').each(function(comment){// comment
    var post_id = comment.id.substr(2);
    $$("#"+comment.id+" pre[name=code]").each(function(pre, index){
      var location = window.location;
      source_url = location.protocol + "//" + location.host + location.pathname + location.search;
      source_url += "#" + comment.id;
      pre.writeAttribute('codeable_id', post_id);
      pre.writeAttribute('codeable_type', "Post");
      pre.writeAttribute('source_url', source_url);
      pre.writeAttribute('pre_index', index);
      pre.writeAttribute('title', 'Java RPC通信机制之RMI');
    });
  });
  code_favorites_init();

  fix_image_size($$('div.blog_content img'), 700);
  function quote_comment(id) {
    new Ajax.Request('/editor/quote', {
      parameters: {'id':id, 'type':'Post'},
      onSuccess:function(response){editor.bbcode_editor.textarea.insertAfterSelection(response.responseText);
        Element.scrollTo(editor.bbcode_editor.textarea.element);}
    });
  }
</script>



        </div>

        <div id="local">
          <div class="local_top"></div>
          <div id="blog_owner">
            <div id="blog_owner_logo"><a href="http://jdlsfl.iteye.com/"><img alt="jdlsfl的博客" class="logo" src="./Java RPC通信机制之RMI - - ITeye技术网站_files/5040df9c-ce9c-3a60-a153-6945b134ddc6.jpg" title="jdlsfl的博客: "></a></div>
            <div id="blog_owner_name">jdlsfl</div>
          </div>
          <div id="blog_actions">
            <ul>
              <li>浏览: 46250 次</li>
              <li>性别: <img alt="Icon_minigender_1" src="./Java RPC通信机制之RMI - - ITeye技术网站_files/icon_minigender_1.gif" title="男"></li>
              <li>来自: 北京</li>
              <li><img src="./Java RPC通信机制之RMI - - ITeye技术网站_files/offline.gif"></li>
              <li>
                <a href="http://jdlsfl.iteye.com/blog/profile" class="profile">详细资料</a>
                <a href="http://jdlsfl.iteye.com/blog/guest_book" class="guest_book">留言簿</a>
              </li>
              
            </ul>
            <h5>搜索本博客</h5>
            <form action="http://jdlsfl.iteye.com/blog/search" method="get">              <input class="text" id="query" name="query" style="margin-left: 10px;width: 110px;" type="text">
              <input class="submit" type="submit" value="搜索">
            </form>          </div>
          
            <div id="user_visits" class="clearfix">
              <h5>最近访客 <span style="font-weight:normal;font-size:12px;padding-left:30px;"><a href="http://jdlsfl.iteye.com/blog/user_visits">&gt;&gt;更多访客</a></span></h5>
              
                <div class="user_visit">
                  <div class="logo"><a href="http://a21989.iteye.com/" target="_blank"><img alt="a21989的博客" class="logo" src="./Java RPC通信机制之RMI - - ITeye技术网站_files/user-logo-thumb.gif" title="a21989的博客: "></a></div>
                  <div class="left"><a href="http://a21989.iteye.com/" target="_blank">a21989</a></div>
                </div>
              
                <div class="user_visit">
                  <div class="logo"><a href="http://moqiao114.iteye.com/" target="_blank"><img alt="moqiao114的博客" class="logo" src="./Java RPC通信机制之RMI - - ITeye技术网站_files/user-logo-thumb.gif" title="moqiao114的博客: 单调的生活"></a></div>
                  <div class="left"><a href="http://moqiao114.iteye.com/" target="_blank">moqiao114</a></div>
                </div>
              
                <div class="user_visit">
                  <div class="logo"><a href="http://jiachunyanlove-126-com.iteye.com/" target="_blank"><img alt="借的JAVA书学JAVA的博客" class="logo" src="./Java RPC通信机制之RMI - - ITeye技术网站_files/531f481c-2d54-31bf-910e-1f3a28c65a36-thumb.gif" title="借的JAVA书学JAVA的博客: "></a></div>
                  <div class="left"><a href="http://jiachunyanlove-126-com.iteye.com/" target="_blank">借的JAVA书学JAVA</a></div>
                </div>
              
                <div class="user_visit">
                  <div class="logo"><a href="http://zdz8207.iteye.com/" target="_blank"><img alt="zdz8207的博客" class="logo" src="./Java RPC通信机制之RMI - - ITeye技术网站_files/fd7f99b7-6cfe-3d51-95ec-9cda8f46eab8-thumb.gif" title="zdz8207的博客: zdz8207"></a></div>
                  <div class="left"><a href="http://zdz8207.iteye.com/" target="_blank">zdz8207</a></div>
                </div>
              
            </div>
          
                      <div id="blog_menu">
              <h5>博客分类</h5>
              <ul>
                <li><a href="http://jdlsfl.iteye.com/">全部博客 (109)</a></li>
                
                  <li><a href="http://jdlsfl.iteye.com/category/34485">Web应用 (3)</a></li>
                
                  <li><a href="http://jdlsfl.iteye.com/category/34486">Java (2)</a></li>
                
                  <li><a href="http://jdlsfl.iteye.com/category/34487">jsp (0)</a></li>
                
                  <li><a href="http://jdlsfl.iteye.com/category/34488">ejb (4)</a></li>
                
                  <li><a href="http://jdlsfl.iteye.com/category/34489">jms (0)</a></li>
                
                  <li><a href="http://jdlsfl.iteye.com/category/34490">Java EE (4)</a></li>
                
              </ul>
            </div>
            
            
              <div id="guest_books">
                <h5>我的留言簿 <span style="font-weight:normal;font-size:12px;padding-left:20px;"><a href="http://jdlsfl.iteye.com/blog/guest_book">&gt;&gt;更多留言</a></span></h5>
                <ul>
                  
                    <li>
                      请问一下javaeye热点论坛的所有论坛热点的pdf电子书都在什么地方下载呢，有几 ...<br>
                      -- by <a href="http://jdlsfl.iteye.com/blog/guest_book#25796">jimoshutong</a>
                    </li>
                  
                </ul>
              </div>
            
            <div id="blog_others">
              <h5>其他分类</h5>
              <ul>
                <li><a href="http://jdlsfl.iteye.com/blog/favorite">我的收藏</a> (19)</li>
                <li><a href="http://jdlsfl.iteye.com/blog/code_favorite">我的代码</a> (0)</li>
                                                <li><a href="http://jdlsfl.iteye.com/blog/topic">我的论坛主题帖</a> (0)</li>
                <li><a href="http://jdlsfl.iteye.com/blog/post">我的所有论坛帖</a> (4)</li>
                <li><a href="http://jdlsfl.iteye.com/blog/article">我的精华良好帖</a> (0)</li>
                              </ul>
            </div>
            
            <div id="recent_groups">
              <h5>最近加入群组</h5>
              <ul>
                
                  <li><a href="http://dojo.group.iteye.com/">dojo</a></li>
                
                  <li><a href="http://tapestrying.group.iteye.com/">Tapestry</a></li>
                
                  <li><a href="http://jbpm.group.iteye.com/">JBPM @net</a></li>
                
                  <li><a href="http://ecside.group.iteye.com/">GT-Grid</a></li>
                
                  <li><a href="http://ext.group.iteye.com/">EXT</a></li>
                
              </ul>
            </div>
            
                          <div id="month_blogs">
                <h5>存档</h5>
                <ul>
                  
                    <li><a href="http://jdlsfl.iteye.com/blog/monthblog/2009-02">2009-02</a> (2)</li>
                  
                    <li><a href="http://jdlsfl.iteye.com/blog/monthblog/2008-12">2008-12</a> (2)</li>
                  
                    <li><a href="http://jdlsfl.iteye.com/blog/monthblog/2008-06">2008-06</a> (6)</li>
                  
                  <li><a href="http://jdlsfl.iteye.com/blog/monthblog_more">更多存档...</a></li>
                </ul>
              </div>
                        <div id="comments_top">
              <h5>评论排行榜</h5>
              <ul>
                
              </ul>
            </div>
            <div id="rss">
              <ul>
                <li><a href="http://jdlsfl.iteye.com/rss" target="_blank"><img alt="Rss" src="./Java RPC通信机制之RMI - - ITeye技术网站_files/rss.png"></a></li>
                <li><a href="http://fusion.google.com/add?feedurl=http://jdlsfl.iteye.com/rss" target="_blank"><img alt="Rss_google" src="./Java RPC通信机制之RMI - - ITeye技术网站_files/rss_google.gif"></a></li>
              </ul>
            </div>
            <div class="local_bottom"></div>
          
        </div>
      </div>

      <div id="footer" class="clearfix">
        <div id="copyright">
          <hr>
          声明：ITeye文章版权属于作者，受法律保护。没有作者书面许可不得转载。若作者同意转载，必须以超链接形式标明文章原始出处和作者。<br>
          © 2003-2011 ITeye.com.   All rights reserved.  [ 京ICP证110151号 ]
        </div>
      </div>
    </div>
    <script type="text/javascript">
  document.write("<img src='http://stat.iteye.com/?url="+ encodeURIComponent(document.location.href) + "&referrer=" + encodeURIComponent(document.referrer) + "&user_id=' width='0' height='0' />");
</script><img src="./Java RPC通信机制之RMI - - ITeye技术网站_files/saved_resource" width="0" height="0">

    
  

</body></html>